package com.example.shaidemo;

import androidx.appcompat.app.AppCompatActivity;

import android.app.Activity;
import android.app.ListActivity;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.SimpleAdapter;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class UploadActivity extends AppCompatActivity {
    ListView listView;
    SimpleAdapter simpleAdapter;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_upload);

        listView = findViewById(R.id.upload_record);
        List<Map<String,String>> uploadList = UploadData();
        simpleAdapter = new SimpleAdapter(this,uploadList,
                R.layout.upload_list_view,
                new String[]{"title","status","time","company","majority","salary"},
                new int[]{R.id.upload_title,R.id.upload_status,R.id.upload_time,R.id.uploadText_1,R.id.uploadText_2,R.id.uploadText_3});
        listView.setAdapter(simpleAdapter);
    }

    public List<Map<String,String>> UploadData(){
        //获取原始数据
        List<Map<String,String>> upload = new ArrayList<>();
        //添加新上传数据
        //防杀熟
        if(getSharedPreferences("newTips", Activity.MODE_PRIVATE) != null){
            SharedPreferences sharedPreferences = getSharedPreferences("newTips", Activity.MODE_PRIVATE);
            String te = sharedPreferences.getString("class","");
            if(te.length() >1){
                //读取数据
                Map map = new HashMap();
                map.put("title",sharedPreferences.getString("class"," "));
                map.put("status",sharedPreferences.getString("status"," "));
                map.put("time",sharedPreferences.getString("time"," "));
                map.put("company", sharedPreferences.getString("title"," "));
                map.put("majority",sharedPreferences.getString("type"," "));
                String content = sharedPreferences.getString("content"," ");
                int end = content.length() >= 15 ? 15 : content.length();
                map.put("salary",content.substring(0,end));
                upload.add(map);
            }
        }
        //打车
        if(getSharedPreferences("newCar", Activity.MODE_PRIVATE) != null){
            SharedPreferences sharedPreferences = getSharedPreferences("newCar", Activity.MODE_PRIVATE);
            String te = sharedPreferences.getString("class","");
            if(te.length() >1){
                //读取数据
                Map map = new HashMap();
                map.put("title",sharedPreferences.getString("class"," "));
                map.put("status",sharedPreferences.getString("status"," "));
                map.put("time",sharedPreferences.getString("time"," "));
                map.put("company", sharedPreferences.getString("start"," "));
                map.put("majority",sharedPreferences.getString("end"," "));
                map.put("salary",sharedPreferences.getString("mes"," "));
                upload.add(map);
            }
        }

        //酒店
        if(getSharedPreferences("newHotel", Activity.MODE_PRIVATE) != null){
            SharedPreferences sharedPreferences = getSharedPreferences("newHotel", Activity.MODE_PRIVATE);
            String te = sharedPreferences.getString("class","");
            if(te.length() >1){
                //读取数据
                Map map = new HashMap();
                map.put("title",sharedPreferences.getString("class",""));
                map.put("status",sharedPreferences.getString("status",""));
                map.put("time",sharedPreferences.getString("time",""));
                map.put("company", sharedPreferences.getString("city",""));
                map.put("majority",sharedPreferences.getString("mes",""));
                map.put("salary",sharedPreferences.getString("price",""));
                upload.add(map);
            }
        }
        //薪资
        if(getSharedPreferences("newSalary", Activity.MODE_PRIVATE) != null){
            SharedPreferences sharedPreferences = getSharedPreferences("newSalary", Activity.MODE_PRIVATE);
            String te = sharedPreferences.getString("class","");
            if(te.length() > 1){
                //读取数据
                Map map = new HashMap();
                map.put("title",sharedPreferences.getString("class"," "));
                map.put("status",sharedPreferences.getString("status"," "));
                map.put("time",sharedPreferences.getString("time"," "));
                map.put("company", sharedPreferences.getString("mes"," "));
                map.put("majority",sharedPreferences.getString("occupation"," "));
                map.put("salary",sharedPreferences.getString("salary"," "));
                upload.add(map);
            }
        }

        List<Map<String,String>> uploadList = GetData.uploadData();
        upload.addAll(uploadList);

        return upload;
    }
}